bantersnaps on Unsplash
To enable the JavaScript language subset njs along with Nginx, we can install from source. In this guide, I’ll provide info on this setup for Ubuntu 20.04.1 LTS.
First check the downloads page here for the latest stable version: http://nginx.org/en/download.html
We’ll be downloading version 1.18.0, which can be done via:
$ wget http://nginx.org/download/nginx-1.18.0.tar.gz
$ tar -zxvf nginx-1.18.0.tar.gz
Make sure your host machine is up to date and install some necessary packages:
$ sudo apt-get install build-essential
$ sudo apt-get install libpcre3 libpcre3-dev zlib1g zlib1g-dev libssl-dev
If you have already installed Nginx via apt-get, make sure to uninstall before installing from source:
$ sudo apt-get remove nginx nginx-common
Next we’ll download mercurial in order to get the source code for the njs module (ngx_http_js_module).
$ sudo apt-get install mercurial
Now clone the njs module code, configure, and run make.
$ hg clone http://hg.nginx.org/njs
$ cd njs
$ sudo ./configure
$ sudo make
The host machine is now ready to install Nginx from source. Navigate to the download directory and configure the install.
To see the options for the modules that can be included upon configuration use the help option:
I’m going to include the following modules/libraries with my install:
The final configuration command ends up being:
$ ./configure --sbin-path=/usr/bin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --with-pcre --pid-path=/var/run/nginx.pid --with-http_ssl_module --with-http_auth_request_module --modules-path=/usr/local/nginx/modules --with-http_v2_module --add-module=$HOME/njs/nginx
Note that I’m including the ngx_http_js_module using the --add-module option, which means that it will not be installed as a dynamic module. This also means that the load_module modules/ngx_http_js_module.so directive does not need to be used within my nginx configuration file.
After configuration completes successfully, run make and install:
$ sudo make install
Finally, check that that nginx has been install correctly and start it up:
You can run $ ps aux | grep nginx to make sure the master and worker processes are running. That’s it!
The certbot installation instructions can be found from certbot.eff.org. More specifically, for ubuntu check here: https://certbot.eff.org/lets-encrypt/ubuntufocal-nginx
As a quick reference, here are a list of commands from their guide I typically use to install certbot:
$ sudo snap install core; sudo snap refresh core
$ apt-get remove certbot
$ sudo snap install --classic certbot
$ sudo ln -s /snap/bin/certbot /usr/bin/certbot